package top.bug.blog.common;

/**
 * @author <a href="https://github.com/jiusi66">九思.</a>
 * @email 10837907@qq.com
 * @from <a href="https://www.52bug.top">递归茶馆-www.52bug.top</a>
 * @description 用户上下文对象
 */
public class UserContext {
    private static final InheritableThreadLocal<String> USER_ID_THREAD_LOCAL = new InheritableThreadLocal<>();

    /**
     * 设置用户ID
     */
    public static void setUserId(String userId) {
        USER_ID_THREAD_LOCAL.set(userId);
    }

    /**
     * 获取当前线程的用户ID
     */
    public static String getUserId() {
        return USER_ID_THREAD_LOCAL.get();
    }

    /**
     * 清除用户ID
     */
    public static void clear() {
        USER_ID_THREAD_LOCAL.remove();
    }
}